﻿using System;
using System.Collections.Generic;

namespace ExtensionMethodExtravaganza
{
	public static class ArrayExtensions
	{
		public static T[] Remove<T>(this T[] array, Predicate<T> condition)
		{
			var list = new List<T>();
			
			foreach (var item in array)
			{
				if (!condition(item))
				{
					list.Add(item);
				}
			}

			return list.ToArray();
		}

		public static T[] Remove<T>(this T[] array, T item)
		{
			var list = new List<T>(array);
			list.Remove(item);

			return list.ToArray();
		}

		public static T[] RemoveAt<T>(this T[] array, int index)
		{
			var list = new List<T>(array);
			list.RemoveAt(index);

			return list.ToArray();
		}
	}
}
